/**
 * 
 */
package info.sswap.ontologies.modularity;


import info.sswap.ontologies.modularity.repo.RepositoryEntry;

import java.net.URI;

/**
 * A Java bean to hold information regarding a specific ontology, in particular:
 * 
 * Logical URI
 * Physical URI
 * Repository entry, if stored locally
 * 
 * @author Pavel Klinov
 *
 */
public class OntologyDescriptor {

	private final URI mLogicalURI;
	private final URI mPhysicalURI;
	private final RepositoryEntry mRepoEntry;
	
	public OntologyDescriptor(URI logURI) {
		mLogicalURI = logURI;
		mRepoEntry = null;
		mPhysicalURI = null;
	}
	
	public OntologyDescriptor(RepositoryEntry entry) {
		mLogicalURI = entry.getURI();
		mRepoEntry = entry;
		mPhysicalURI = null;
	}
	
	public OntologyDescriptor(URI logURI, URI physURI) {
		mLogicalURI = logURI;
		mRepoEntry = null;
		mPhysicalURI = physURI;
	}	

	public URI getLogicalURI() {
		
		return mLogicalURI;
	}
	
	public URI getPhysicalURI() {
		
		return mPhysicalURI;
	}
	
	public RepositoryEntry getRepositoryEntry() {
		
		return mRepoEntry;
	}
	
	public boolean isDereferenceable() {
		return mPhysicalURI != null;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof OntologyDescriptor) {
			return ((OntologyDescriptor)obj).getLogicalURI().equals(mLogicalURI);
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return mLogicalURI.hashCode();
	}

	@Override
	public String toString() {
		if (isDereferenceable()) {
			return "physical: " + mPhysicalURI.toString();
		}
		else {
			return "logical: " + mLogicalURI.toString();
		}
	}
	
	
}